<template>
	<view class="register">
		<u-navbar :placeholder='true' bgColor='transparent' title="" :autoBack="false">
			<view class="leftSlot" slot="left" @tap="pageBack(1)">
				<view class="iconfont icon-fanhui">
				</view>
			</view>
		</u-navbar>
		<image class="bg-img" src="@/static/images/register-bg.png"></image>
		<view class="title">欢迎注册</view>
		<view class="logo">LOGO</view>
		<view class="main">
			<u--form labelPosition="top" :model="model" :rules="rules" ref="uForm" :labelStyle="labelStyle">
				<u-form-item label="账号" prop="account">
					<u--input :customStyle="accountCustomStyle" v-model="model.account" border="none"
						placeholder="请输入手机号" />
				</u-form-item>
				<u-form-item label="密码" prop="password">
					<!-- 注意：由于兼容性差异，如果需要使用前后插槽，nvue下需使用u--input，非nvue下需使用u-input -->
					<!-- #ifndef APP-NVUE -->
					<u-input :type="passwordType" :customStyle="accountCustomStyle" v-model="model.password"
						border="none" placeholder="请输入密码">
					<!-- #endif -->
						<!-- #ifdef APP-NVUE -->
						<u--input :customStyle="accountCustomStyle" v-model="model.password" border="none"
							placeholder="请输入密码">
						<!-- #endif -->
							<template slot="suffix">
								<u-icon name="eye" @tap="passwordType=passwordType==='text'?'password':'text'"></u-icon>
								<!-- <u-button @tap="getCode" :text="tips" type="success" size="mini"></u-button> -->
							</template>
					<!-- #ifndef APP-NVUE -->
					</u-input>
					<!-- #endif -->
					<!-- #ifdef APP-NVUE -->
					</u--input>
					<!-- #endif -->
				</u-form-item>
				<u-form-item label="验证码" prop="code">
					<!-- 注意：由于兼容性差异，如果需要使用前后插槽，nvue下需使用u--input，非nvue下需使用u-input -->
					<!-- #ifndef APP-NVUE -->
					<u-input :customStyle="accountCustomStyle" v-model="model.code" border="none" placeholder="请输入验证码">
					<!-- #endif -->
						<!-- #ifdef APP-NVUE -->
						<u--input :customStyle="accountCustomStyle" v-model="model.code" border="none"
							placeholder="请输入验证码">
						<!-- #endif -->
							<template slot="suffix">
								<u-code :seconds="seconds" @end="codeEnd" @start="codeStart" ref="uCode"
									@change="codeChange"></u-code>
								<text class="send-code" @click="handleClickSendCode">{{code}}</text>
							</template>
					<!-- #ifndef APP-NVUE -->
					</u-input>
					<!-- #endif -->
					<!-- #ifdef APP-NVUE -->
					</u--input>
					<!-- #endif -->
				</u-form-item>
			</u--form>
			<view class="account-button" @click="handleClickAccountLogin">注册</view>
			<view class="bottom">
				<loginAgreement :chooes="agreement_chooes" @choose="(e)=>agreement_chooes=e"></loginAgreement>
			</view>
		</view>
	</view>
</template>


<script>
	import loginAgreement from './components/loginAgreement.vue';
	export default {
		components: {
			loginAgreement
		},
		data() {
			return {
				labelStyle: {
					fontSize: "32rpx",
					fontWeight: 500,
					marginLeft: "32rpx",
					width: "200rpx"
				},
				accountCustomStyle: {
					height: "96rpx",
					borderRadius: "24rpx",
					background: "rgba(246, 248, 252, 1)",
					padding: "0 36rpx",
				},
				model: {
					account: "",
					password: "",
					code: ""
				},
				passwordType: "password",
				rules: {
					account: [{
							required: true,
							message: '请输入账号',
							trigger: ['change', 'blur'],
						},
						// {
						// 	// 自定义验证函数，见上说明
						// 	validator: (rule, value, callback) => {
						// 		// 上面有说，返回true表示校验通过，返回false表示不通过
						// 		// uni.$u.test.mobile()就是返回true或者false的
						// 		return uni.$u.test.mobile(value);
						// 	},
						// 	message: '账号不正确',
						// 	// 触发器可以同时用blur和change
						// 	trigger: ['change', 'blur'],
						// }
					],
					password: [{
						required: true,
						message: "请输入密码",
						trigger: ['change', 'blur']
					}]
				},
				//已阅读并同意
				agreement_chooes: true,
				code: "发送验证码",
				seconds: 60
			}
		},
		onReady() {
			//onReady 为uni-app支持的生命周期之一
			this.$refs.uForm.setRules(this.rules)
		},
		methods: {
			/**
			 * 账号登录
			 */
			handleClickAccountLogin() {
				this.$refs.uForm.validate().then(res => {
					uni.$u.toast('校验通过')
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
				console.log("账号登录");
			},
			handleClickForgotPassword() {
				console.log("忘记密码");
			},
			handleClickRegister() {
				console.log("注册");
			},
			/**
			 * 发送验证码
			 */
			handleClickSendCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			codeEnd() {

			},
			codeStart() {

			},
			codeChange(text) {
				this.code = text;
			},
		}
	}
</script>


<style lang="scss" scoped>
	.leftSlot{
		left: 32rpx;
		width: 48rpx;
		height: 48rpx;
		background: rgba(255, 255, 255, 1);
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50%;
	}
	.register {
		overflow: hidden;
		width: 100vw;
		height: 100vh;

		.bg-img {
			position: absolute;
			width: 100%;
			height: 100vh;
			z-index: -1;
			top: 0;
		}

		.title {
			position: absolute;
			left: 40rpx;
			top: 302rpx;
			font-size: 56rpx;
			font-weight: 500;
		}

		.logo {
			position: absolute;
			left: 40rpx;
			top: 174rpx;
			font-size: 28rpx;
			font-weight: 600;
			color: $theme-color;
			width: 112rpx;
			height: 112rpx;
			background-color: #FFF;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 112rpx;
		}

		.main {
			position: absolute;
			background-color: #FFF;
			width: 100%;
			height: 1188rpx;
			top: 438rpx;
			border-radius: 48.66rpx;

			::v-deep .u-form {
				margin: 40rpx;

				.send-code {
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(76, 212, 230, 1);
				}
			}

			.account-button {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 44px;
				margin: 40rpx;
				background: $theme-color;
				text-align: center;
				border-radius: 24rpx;
				color: #FFF;
				font-size: 32rpx;
			}
		}
	}
</style>